package com.liu.netty.service;

import com.liu.netty.dao.DriverDao;
import com.liu.netty.dao.ErrorInfoDao;
import com.liu.netty.dao.RunInfoDao;
import com.liu.netty.entity.Driver;
import com.liu.netty.entity.ErrorInfo;
import com.liu.netty.entity.RunInfo;
import com.liu.netty.pojo.Message;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import util.IdWorker;

import javax.transaction.Transactional;


@Service
@Transactional
public class ErrorInfoService {

    @Autowired
    private ErrorInfoDao errorInfoDao;

    @Autowired
    private IdWorker idWorker;

    @Autowired
    private DriverDao driverDao;

     public void addErrorInfo(ErrorInfo errorInfo ,String objectAddress){
         errorInfo.setId(idWorker.nextId()+"");

         Driver driver = driverDao.findByObjectAddress(objectAddress);
         errorInfo.setDriver(driver);
         errorInfoDao.save(errorInfo);
     }

     public void addErrorInfoDaoFromClient(Message message ){
         ErrorInfo  errorInfo = new ErrorInfo();
         BeanUtils.copyProperties(message,errorInfo);
         addErrorInfo(errorInfo,message.getObjectAddress());



     }

}
